<!--
 * Copyright © 2023
 * @Author: zhangxiang
 * @Date: 2023-07-18 15:29:41
 * @LastEditors: zhangxiang
 * @LastEditTime: 2023-07-21 18:11:59
 * @Description:
 *
-->
<template>
  <div class="vpc-network-config">
    <CreateAliyun
      v-if="parentCloudProvider === '阿里云'"
      ref="createForm"
      :cloud-select="parentCloudProvider"
      :scene="'orchestrate'"
      :info="form"
    />
    <CreateHuawei
      v-if="parentCloudProvider === '华为云'"
      ref="createForm"
      :cloud-select="parentCloudProvider"
      :scene="'orchestrate'"
      :info="form"
    />
    <CreateTencent
      v-if="parentCloudProvider === '腾讯云'"
      ref="createForm"
      :cloud-select="parentCloudProvider"
      :scene="'orchestrate'"
      :info="form"
    />
  </div>
</template>

<script>
import commonMixin from './commonMixin.js'
import CreateAliyun from '@/views/cn-resource/network/public/CreateAliyun.vue'
import CreateTencent from '@/views/cn-resource/network/public/CreateTencent.vue'
import CreateHuawei from '@/views/cn-resource/network/public/CreateHuawei.vue'

export default {
  components: {
    CreateAliyun,
    CreateHuawei,
    CreateTencent
  },
  mixins: [commonMixin],
  props: ['params', 'GraphApi', 'cell'],
  data() {
    return {
      form: {
        name: '',
        cpRegionId: '',
        cidr: '',
        desc: ''
      }
    }
  },
  mounted() {
    this.form = Object.assign(
      {},
      this.form,
      this.params.attribute || {},
      this.parentAttribute
    )
  },
  methods: {
    /**
     * @description: 保存配置
     * @param {*} callback
     * @return {*}
     */
    saveConfig(callback) {
      this.$refs.createForm.validateForm((form) => {
        const businessData = JSON.parse(JSON.stringify(this.params))
        businessData.attribute = form
        this.GraphApi.setObjectData(
          this.params.id,
          JSON.stringify(businessData)
        )
        this.cell.setValue(businessData.attribute.name)
        this.GraphApi.refresh(this.cell)
        callback()
      })
    }
  }
}
</script>
